<?php
    require('./Utils.php');

    if ($_FILES["file"]["error"] > 0)
    {
        echo "错误：" . $_FILES["file"]["error"] . "<br>";
    }
    else
    {
        $dir = "upload/";
        $file_name = $_FILES["file"]["name"];

        $file_suffix = substr($file_name, strripos($file_name,'.'));
        $file_name = substr($file_name , 0, strripos($file_name,'.'));

        $date = date_create();
        $tiem_number = date_timestamp_get($date);

        $file_name = $file_name ."_".$tiem_number . $file_suffix;

        $path = $dir.$file_name;


        $result = move_uploaded_file($_FILES["file"]["tmp_name"],$path);

        $data = array();
        $data['imgUrl'] = $path;

        if($result){
            getJson(200, '上传成功', $data);
        }else{
            getJson(500, '上传失败', $data);
        }
    }
?>